package wangwenjun.phase2.concurrencypattern.eventbus.google.demo06;

import com.google.common.eventbus.EventBus;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import wangwenjun.phase2.concurrencypattern.eventbus.google.demo04.Apple;
import wangwenjun.phase2.concurrencypattern.eventbus.google.demo04.Fruit;

/**
 * @author ChangLiang
 * @date 2020/6/19
 */
@Slf4j
public class AppTest {

    @Test
    @DisplayName("test dead event")
    public void test() {
        final EventBus eventBus = new EventBus("dead-event-bus");
        eventBus.register(new DeadEventListener());
        String itemId = "1";
        eventBus.post(itemId);
        log.info("post the item id:{}",itemId);
    }

    @Test
    @DisplayName("test dead event")
    public void test3() {
        final EventBus eventBus = new EventBus("dead-event-bus");
        eventBus.register(new DeadEventListener());
        Integer itemId = 1;
        eventBus.post(itemId);
        log.info("post the item id:{}",itemId);
    }

    @Test
    @DisplayName("test dead event")
    public void test4() {
        final EventBus eventBus = new EventBus("dead-event-bus");
        eventBus.register(new DeadEventListener());
        Fruit apple = new Apple("an apple");
        eventBus.post(apple);
        log.info("post the item id:{}",apple);
    }

    @Test
    @DisplayName("test dead event")
    public void test2() {
        final EventBus eventBus = new EventBus("dead-event-bus") {
            @Override
            public String toString() {
                return "DEAD-EVENT-BUS";
            }
        };
        eventBus.register(new DeadEventListener());
        String itemId = "1";
        eventBus.post(itemId);
        log.info("post the item id:{}",itemId);
    }
}
